
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of proyecto
 *
 * @author konda
 */
class proyecto extends CI_Controller{
    //put your code here
    
    public function __construct() {
        parent::__construct();      
         //library
         $this->load->library('form_validation');
         //helper
         $this->load->helper(array('form','url'));
         //model
         $this->load->model('m_proyecto');
         $this->load->model('m_generic');

         //initialize los valores 
         //parameters
         $dataInitialize=array();
         $dataInitialize['table']='sc_pyto';
         $dataInitialize['id_table']='id';
         $this->m_generic->initialize($dataInitialize);
     


    }
    
    
    
    public function Index()
    {
         ///////////////////////////////////////////////////////
         //Data
         //title page
         $data['title']="Proyecto";
         $data['view']="v_proyecto";

         $data['menu_header']   = $this->menu_header();
         $data['menu_left']     = $this->menu_left();
         
         $this->load->view('template/header.php',$data);
         $this->load->view('template/content.php',$data);
         $this->load->view('template/footer.php');
          
    }
    
   
    /**
     * Add row receiving from 
     * parameter
     */
    public function add()
    {
        $pyto_id=$_POST['pyto_id'];
        $dpto_id=$_POST['dpto_id'];
        $lcdad_id=$_POST['lcdad_id'];
        $pyto_aporte=$_POST['pyto_aporte'];
        $pyto_cant=$_POST['pyto_cant'];
        $pyto_evaluacion=$_POST['pyto_evaluacion'];
        
        //$this->form_validation->set_rules('dpto_id','dpto_id',required);
        $this->form_validation->set_rules('pyto_id','proyecto','trim|required|xss_clean');
        $this->form_validation->set_rules('dpto_id','departamento','trim|required|xss_clean');
        $this->form_validation->set_rules('lcdad_id','localidad','trim|required|xss_clean');
        
        if($this->form_validation->run()==FALSE)
        {  //error
            
        }else
        {
            $data=array(
                'pyto_id'=>$pyto_id,
                'dpto_id'=>$dpto_id,
                'lcdad_id'=>$lcdad_id,
                'pyto_aporte' =>$pyto_aporte,
                'pyto_cant'   =>$pyto_cant,
                'pyto_evaluacion'=>$pyto_evaluacion
            );
            
           //add
            $this->m_generic->add($data);
            
            //return value 
            //Return result to jTable
             $jTableResult = array();
             //cabecera header
            $jTableResult['Result']  = "OK";
            $jTableResult['Record'] = $this->m_generic->getRowLastInsert();
            print json_encode($jTableResult);
            
        }
        
    }
   
    /**Update 
       * row of table proyecto
       **/
    public function update()
    {

        $id=$_POST['id'];
        $pyto_id=$_POST['pyto_id'];
        $dpto_id=$_POST['dpto_id'];
        $lcdad_id=$_POST['lcdad_id'];
        $pyto_aporte=$_POST['pyto_aporte'];
        $pyto_cant=$_POST['pyto_cant'];
        $pyto_evaluacion=$_POST['pyto_evaluacion'];
        
        //$this->form_validation->set_rules('dpto_id','dpto_id',required);
        $this->form_validation->set_rules('pyto_id','proyecto','trim|required|xss_clean');
        $this->form_validation->set_rules('dpto_id','departamento','trim|required|xss_clean');
        $this->form_validation->set_rules('lcdad_id','localidad','trim|required|xss_clean');
        
        if($this->form_validation->run()==FALSE)
        {  //error
            
        }else
        {
            $data=array(
                'pyto_id'=>$pyto_id,
                'dpto_id'=>$dpto_id,
                'lcdad_id'=>$lcdad_id,
                'pyto_aporte' =>$pyto_aporte,
                'pyto_cant'   =>$pyto_cant,
                'pyto_evaluacion'=>$pyto_evaluacion
            );
            
           //update
            $this->m_generic->update($id,$data);
            
            //return value 
            //Return result to jTable
             $jTableResult = array();
             //cabecera header
            $jTableResult['Result']  = "OK";
            $jTableResult['Record'] = $this->m_generic->getRowLastInsert();
            print json_encode($jTableResult);
            
        }
    }
    
    /**
     * Function get All proyectos
     */
    public function getList()
    {
        $rows=array();
        $rows=$this->m_generic->getAll();
        $rows_count=$this->m_generic->getRowCount();
       
        //Return result to jTable
       $jTableResult = array();
       $jTableResult['Result'] = "OK";
       $jTableResult['Records'] = $rows;
       $jTableResult['TotalRecordCount']=$rows_count;
       print json_encode($jTableResult);
        
   }
    
    public function delete()
    {
        $row_id=$_POST['id'];
        $this->m_proyecto->delete($row_id);
        //Return result to jTable
        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        print json_encode($jTableResult);
    }
    
    
    
    //////////////////////////////////////////////////////////////////
    
    
    /**
     * Functions of variables
     * 
     */
    
     public function menu_header()
    {

       $menu_header="<div class=\"navbar navbar-fixed-top navbar-inverse\">";
       $menu_header.="<div class=\"navbar-inner\">";
       $menu_header.="<ul class=\"nav\">";
       $menu_header.="<li class=\"active\">";
       $menu_header.=anchor("inicio","Inicio");
       $menu_header.="</li>";

       $menu_header.="<li class=\"divider-vertical\"></li>";
       $menu_header.="<li>";
       $menu_header.=anchor("map","Mapas");
       $menu_header.="</li>";
       $menu_header.="</ul>";
       $menu_header.="<ul class=\"nav pull-right\">";
       $menu_header.="<li>";
       $menu_header.="<a href=\"#\">";
       $menu_header.="Usuario1";
       $menu_header.="</a>";
       $menu_header.="</li>";
       $menu_header.="<li class=\"divider-vertical\"></li>";
       $menu_header.="<li class=\"dropdown\" data-no-collapse=\"true\">";
       $menu_header.="<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\">";
       $menu_header.="Configuration<b class=\"caret\"></b>";
       $menu_header.="</a>";
       
       $menu_header.="<ul class=\"dropdown-menu\">";
       $menu_header.="<li>";
       $menu_header.=anchor("logout","Salir");
       $menu_header.="</li>";
       $menu_header.="</ul>";
       
       $menu_header.="</li>"; //class dropdown
       $menu_header.="</ul>"; //class nav pull right
       $menu_header.="</div>";
       $menu_header.="</div>";

       //black header
       //$menu_header.="<div class=\"gbx1\"></div>"; 
       
       return $menu_header;
    }
    
    
    
    
    public function menu_left()
    {
        $menu_left="<div id=\"leftCol\">";
        $menu_left.="<ul id=\"menu\">";
        $menu_left.="<li class=\"ui-state-highlight\">";
        $menu_left.=anchor("proyecto","Proyecto");
        $menu_left.="</li>";
        $menu_left.="<li>";
        $menu_left.=anchor("departamento","Departamento");
        $menu_left.="</li>";
        $menu_left.="<li>";
        $menu_left.=anchor("localidad","Localidad");
        $menu_left.="</li>";
        $menu_left.="<li>";
        $menu_left.=anchor("municipio","Municipio");
        $menu_left.="</li>";
        $menu_left.="<li>";
        $menu_left.=anchor("obra","Obras");
        $menu_left.="</li>";
        $menu_left.="</ul>";
        $menu_left.="</div>";  
        
        return $menu_left;
              
    }
        
}

?>
